/**
 * 销售回款预测 - 自动生成页面
 * @author liuw
 * @date 2019/09/02
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            form: {
                YEAR_: null,
                MONTH_: null,
                ORG_NAME_:null,
                ORG_ID:null
            },
            rules: {
                YEAR_: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                MONTH_: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions:{
                crm_gwat550_qb:app.datas_("crm_gwat550_qb")
            }
        },
        callObj
    ;

    var Gwat550Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwat550_auto',
                _loadTplsFull: [/*{
                    dom: 'common_open_orgs', tpl: 'common/_open_orgs'
                }*/
                    {
                        dom: 'common_open_window', tpl: 'common/_open_window'
                    }
                ]
            }, win);
        },

        autoGeneration: function () {
            app.ajax({
                xurl: 'crm/gwat550/autoGeneration',
                xdata: vueData.form,
                loading: true,
                confirm: {msg: "是否执行自动生成？"},
                okmsg: '自动生成成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwat550').reloadTableCurr();
                        self._closeTpl();
                    }
                }
            });
        },

        _call: function (tagData) {
            vueData.form.YEAR_ = '';
            vueData.form.MONTH_ = '';
            vueData.form.ORG_NAME_ = '';
            vueData.form.ORG_ID = '';
        },
        _ready: function () {
            var vue = new Vue({
                el: '#gwat550_auto',
                data: vueData,
                methods: {
                    cancel: function () {
                        self._closeTpl();
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                self.autoGeneration();
                            }
                        });
                    },
                    openOrg:function () {
                        /*self._openTplFull({
                            tag: 'common_open_orgs',
                            tagData: {
                                cb: function (data) {
                                    vueData.form.ORG_ID = data.ID;
                                    vueData.form.ORG_NAME_ = data.NAME + ' '+data.ID;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择服务组织',
                                area: ['600px', '430px']
                            }
                        });*/
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_sys_org',
                                    columnList: [
                                        {label: '组织ID', prop: 'ID', width: '150'},
                                        {label: '组织名称', prop: 'NAME', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.ORG_ID = data.ID;
                                    vueData.form.ORG_NAME_ = data.NAME + ' '+data.ID;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择服务组织',
                                area: ['600px', '465px']
                            }
                        });
                    }
                },
                watch: {},
                created: function () {
                    self._setEleIsReady('gwat550_auto');
                }
            });
        },

        _lazy: function () {
            this._super();
        }
    });

    return new Gwat550Edit();

});